object ImageInverter
{
	def main() : Unit = 
	{ 
		println(new BWImageTester().Test());
	}
}

class BWImageTester
{
	def Test() : Bool = 
	{
		var bRet : Bool; 
		var myImage : BWImage;
		
		var white : Int;
		var black : Int;
		white = 1;  black = 0;
		bRet = true;

		myImage = new BWImage();
		if(myImage.init(3, 5) == false) {  bRet = false; }
		else
		{
			bRet = bRet && myImage.setPixel(0, 0, black);
			bRet = bRet && myImage.setPixel(0, 1, white);
			bRet = bRet && myImage.setPixel(0, 2, black);
			bRet = bRet && myImage.setPixel(0, 3, white);
			bRet = bRet && myImage.setPixel(1, 0, white);
			bRet = bRet && myImage.setPixel(1, 1, black);
			bRet = bRet && myImage.setPixel(1, 2, white);
			bRet = bRet && myImage.setPixel(1, 3, black);
			bRet = bRet && myImage.setPixel(1, 4, white);
			bRet = bRet && myImage.setPixel(2, 0, black);
			bRet = bRet && myImage.setPixel(2, 1, white);
			bRet = bRet && myImage.setPixel(2, 2, black);
			bRet = bRet && myImage.setPixel(2, 3, white);
			
			if(bRet) { println("image : "); }
			bRet = bRet && myImage.print();
			
			bRet = bRet && myImage.invert();
			if(bRet) { println("image inverted : "); }
			bRet = bRet && myImage.print();
		}
		
		return bRet;
	}
}

class Image
{
	var image : Int[];
	var nSizeX : Int;
	var nSizeY : Int;
	
	def init(sizeX : Int, sizeY : Int) : Bool =
	{
		var bRet : Bool; bRet = true; 
		if(sizeX < 1 || sizeY < 1)
		{
			nSizeX = 0; nSizeY = 0;
			bRet = false;
		}
		else
		{
			nSizeX = sizeX; nSizeY = sizeY;
			image = new Int[nSizeX * nSizeY];
		}
		return true;
	}
	
	def setPixel(x : Int, y : Int, color : Int) : Bool =
	{	
		var bRet : Bool;	bRet = true;
		if(x < 0 || y < 0) { bRet = false; }
		else if(nSizeX < x+1 || nSizeY < y+1) { bRet = false; }
		else { image[(x * nSizeY) + y] = color; }
		
		return bRet;
	}	
}

class BWImage extends Image
{
	def print() : Bool =
	{
		var x : Int;
		var y : Int;
		var line : String; 
		
		line = "";
		x = 0; y = 0;
		
		while(x < nSizeX)
		{
			while(y < nSizeY)
			{
				if(this.isWhite(image[x * nSizeY + y])) 
				{ line = line + " "; }
				else { line = line + "*"; } 
				y = y+1;
			}
			println(line);
			
			line = ""; y = 0;	x = x+1;
		}
		
		return true;
	}
	
	def invert() : Bool = 
	{
		var x : Int;
		var y : Int;
		x = 0; y = 0;
		
		while(x < nSizeX)
		{
			while(y < nSizeY)
			{
				if(this.isWhite(image[x * nSizeY + y])) 
				{ image[x * nSizeY + y] = 0; }
				else { image[x * nSizeY + y] = 1; } 
				y = y+1;
			}
			y = 0; x = x+1;
		}
		
		return true;
	}
	
	def isWhite(pixel : Int) : Bool =
	{
		return !(pixel == 0);
	}
}